<?
/***************************************************************************
 *                                 common.php
 *                            -------------------
 *   Begin                : Thursday, April 16, 2005
 *   Copyright            : (C) 2005 Point and Code
 *   Domain               : http://www.pointandcode.com/
 *   Email                : support@pointandcode.com
 *   Version              : 1.0.0
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

include $root_path . 'template.php';



//
// Get the preferences (template, language).
//
if (file_exists($path_to_home.'/.cpzen'))
{
	$preferences = file($path_to_home.'/.cpzen');
	
	$config['template'] = trim($preferences[0]);
	$config['language'] = $preferences[1];
}
else
{
	$config['template'] = $config['default_template'];
	$config['language'] = $config['default_language'];
};

// Where are the templates located?
$template_path = "templates/".$config['template'].'/';

// Start off the templates
$template = new Template($root_path.$template_path);

//
// Include template config file
//

include $root_path . $template_path . 'template_config.cfg';


//
// Get language
//

require $root_path . 'language/'.$config['language'].'.php';




//
// A few random functions we need
//
function message_die($msg_text = '', $msg_title = '') 
{

	global $root_path;
	global $template_path;

	if(defined('HAS_DIED'))
	{
		die("message_die() was called multiple times. This isn't supposed to happen. Was message_die() used in page_tail.php?");
	}
	
	define(HAS_DIED, 1);
	
	
	if ( empty($template) )
	{
		$template = new Template(root_path . $template_path);
	}
	

	
	if ( $msg_title == '' )
	{
		$msg_title = 'Information';
	}
	
	$template->set_filenames(array(
		'message_body' => $root_path.$template_path.'message_body.tpl')
	);
	
	$template->assign_vars(array(
		'MESSAGE_TITLE' => $msg_title,
		'MESSAGE_TEXT' => $msg_text)
	);
	$template->pparse('message_body');
	
	include($root_path . 'page_tail.php');
	
	exit;


}

function message_done($msg_text = '', $cpanel_output, $return_url, $return_name, $msg_title = '') 
{

	global $root_path;
	global $template_path;
	global $lang;

	if(defined('HAS_DIED'))
	{
		die("message_die() was called multiple times. This isn't supposed to happen. Was message_die() used in page_tail.php?");
	}
	
	define(HAS_DIED, 1);
	
	
	if ( empty($template) )
	{
		$template = new Template(root_path . $template_path);
	}
	

	
	if ( $msg_title == '' )
	{
		$msg_title = 'Information';
	}
	
	$template->set_filenames(array(
		'message_done_body' => $root_path.$template_path.'message_done_body.tpl')
	);

	$cpanel_output = htmlspecialchars($cpanel_output);
	$cpanel_output = str_replace("<br>", "", $cpanel_output);
	$cpanel_output = str_replace("<br />", "", $cpanel_output);
	$cpanel_output = str_replace("<pre>", "", $cpanel_output);
	
	$template->assign_vars(array(
		'MESSAGE_TITLE' => $msg_title,
		'MESSAGE_TEXT' => $msg_text,
		'CPANEL_OUTPUT' => $cpanel_output,
		'RETURN_URL' => $return_url,
		'RETURN_NAME' => $return_name,
		
		'L_CPANEL_SAID' => $lang['cpanel_said'],
		'L_RETURN_TO' => $lang['return_to'],
		'L_PAGE' => $lang['page'],
	));
	$template->pparse('message_done_body');
	
	include($root_path . 'page_tail.php');
	
	exit;


}


?>